<template>
	<view class="main-page">
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="加载中"></u-loading-page>
		<view class="main" v-if="!loadding">
			<view class="menu">
				<view class="title">
					<text>业务功能</text>
				</view>
				<view class="lists">
					<view class="items" v-for="(item, index) in menuData" :key="index" @click="pathTo(item.path)">
						<image class="img" :src="src + item.icons" mode="aspectFit"></image>
						<text>{{item.name}}</text>
					</view>
				</view>
			</view>
			<view class="datas">
				<view class="title">
					<text>交易</text>
				</view>
				<view v-if="dataTotal.trade" class="lists">
					<view class="item" @click="pathTos(1,1)">
						<view class="top">
							<text>昨日</text>
						</view>
						<view class="bottom">
							<text>{{dataTotal.trade.day}}</text>
						</view>
					</view>
					<view class="item" @click="pathTos(1,2)">
						<view class="top">
							<text>本月</text>
						</view>
						<view class="bottom">
							<text>{{dataTotal.trade.month}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="actives">
				<view class="title">
					<text>激活</text>
				</view>
				<view v-if="dataTotal.active" class="lists">
					<view class="item" @click="pathTos(2,1)">
						<view class="top">
							<text>昨日</text>
						</view>
						<view class="bottom">
							<text>{{dataTotal.active.day}}</text>
						</view>
					</view>
					<view class="item" @click="pathTos(2,2)">
						<view class="top">
							<text>本月</text>
						</view>
						<view class="bottom">
							<text>{{dataTotal.active.month}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var util = require('@/util/request.js');
	export default {
		data() {
			return {
				loadding: false,
				menuData: [],
				src: '',
				userinfo: {},
				dataTotal: {},
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo')
			this.src = util.API_URL
			this.getMenu()
			this.getHzyIndexData()
		},
		methods: {
			// 菜单点击
			pathTo(path) {
				uni.navigateTo({
					url: path
				})
			},
			// 数据点击
			pathTos(cid, tid) {
				var path = '/pages/hzy/trade/index'
				if (cid == 2) {
					path = '/pages/hzy/active/index'
				}
				uni.navigateTo({
					url: path + '?type=' + tid
				})
			},
			// 菜单展示
			async getMenu() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'menu/getMenu',
					data: {
						type: 0,
						class: 2
					}
				});
				uni.hideLoading()
				this.loadding = false
				if (res.code == 200) {
					this.menuData = res.data
				}
			},
			// 数据统计
			async getHzyIndexData() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyIndexData'
				});
				if (res.code == 200) {
					this.dataTotal = res.data
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F2F6FC;
	}

	.main-page {
		.main {
			padding: 30rpx;

			.menu {
				background-color: #FFFFFF;

				.title {
					padding: 20rpx 30rpx;
					border-left: 10rpx solid #2979ff;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.lists {
					padding-top: 30rpx;
					display: flex;
					align-items: center;
					flex-wrap: wrap;

					.items {
						margin-bottom: 40rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
						min-width: 25%;

						.img {
							width: 80rpx;
							height: 80rpx;
							margin-bottom: 10rpx;
						}

						text {
							font-size: 28rpx;
						}
					}
				}
			}

			.datas {
				margin-top: 30rpx;
				background-color: #FFFFFF;

				.title {
					padding: 20rpx 30rpx;
					border-left: 10rpx solid #19be6b;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.lists {
					padding: 30rpx 0;
					display: flex;
					align-items: center;
					flex-wrap: wrap;

					.item {
						display: flex;
						flex-direction: column;
						align-items: center;
						min-width: 49%;

						.top {
							margin-bottom: 30rpx;
						}
					}

					.item:nth-child(1) {
						border-right: 1px dashed #c8c9cc;
					}
				}
			}

			.actives {
				margin-top: 30rpx;
				background-color: #FFFFFF;

				.title {
					padding: 20rpx 30rpx;
					border-left: 10rpx solid #ff9900;
					font-weight: bold;
					border-bottom: 1px solid #f4f4f5;
				}

				.lists {
					padding: 30rpx 0;
					display: flex;
					align-items: center;
					flex-wrap: wrap;

					.item {
						display: flex;
						flex-direction: column;
						align-items: center;
						min-width: 49%;

						.top {
							margin-bottom: 30rpx;
						}
						
						.bottom {
							font-size: 34rpx;
						}
					}

					.item:nth-child(1) {
						border-right: 1px dashed #c8c9cc;
					}
				}
			}
		}
	}
</style>